﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Vds2465Telegrams
{
	[TestClass]
	public class UserData_26_BlockStateAll_Test
	{
		[TestMethod]
		[Owner("Frank Eppink")]
		public void Test01_Equals()
		{
			UserData_26_BlockStateAll userData = new UserData_26_BlockStateAll(0x67, 0x23, 0x54, 
					new byte[] { 0xff, 0xaa, 0x55 }, new byte[] { 0xff, 0xaa, 0x55 }, new byte[] { 0xff, 0xaa, 0x55 });

			{
				// completely different type - NOT equal
				object dummyObject = new object();
				Assert.IsFalse(userData.Equals(dummyObject));
			}

			{
				// different derived type 
				UserData_11_Error userData2Compare = new UserData_11_Error(eErrorCode.DataOutOfRange, 0x99);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// same object - equal
				UserData_26_BlockStateAll userData2Compare = new UserData_26_BlockStateAll(userData.Device, userData.Address, userData.AddressAddOn, 
							userData.GetCopyOfInputBytes(), userData.GetCopyOfOutputBytes(), userData.GetCopyOfDisruptionBytes());
				Assert.IsTrue(userData.Equals(userData2Compare));
			}

			{
				// different device
				UserData_26_BlockStateAll userData2Compare = new UserData_26_BlockStateAll((byte)(userData.Device + 1), userData.Address, userData.AddressAddOn,
							userData.GetCopyOfInputBytes(), userData.GetCopyOfOutputBytes(), userData.GetCopyOfDisruptionBytes());
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// different address
				UserData_26_BlockStateAll userData2Compare = new UserData_26_BlockStateAll(userData.Device, (byte)(userData.Address + 1), userData.AddressAddOn,
							userData.GetCopyOfInputBytes(), userData.GetCopyOfOutputBytes(), userData.GetCopyOfDisruptionBytes());
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// different AddressAddOn
				UserData_26_BlockStateAll userData2Compare = new UserData_26_BlockStateAll(userData.Device, userData.Address, (byte)(userData.AddressAddOn + 1),
							userData.GetCopyOfInputBytes(), userData.GetCopyOfOutputBytes(), userData.GetCopyOfDisruptionBytes());
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// different input bytes - one more member
				byte[] inputBytesCopy = userData.GetCopyOfInputBytes();
				byte[] inputBytes2Compare = new byte[inputBytesCopy.Length + 1];
				for (int index = 0; index < inputBytesCopy.Length; index++)
				{
					inputBytes2Compare[index] = inputBytesCopy[index];
				}
				inputBytes2Compare[inputBytesCopy.Length] = 0x55;

				UserData_26_BlockStateAll userData2Compare = new UserData_26_BlockStateAll(userData.Device, userData.Address, userData.AddressAddOn,
							inputBytes2Compare, userData.GetCopyOfOutputBytes(), userData.GetCopyOfDisruptionBytes());
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// different input bytes - one different member
				byte[] inputBytesCopy = userData.GetCopyOfInputBytes();
				byte[] inputBytes2Compare = new byte[inputBytesCopy.Length];
				for (int index = 0; index < inputBytesCopy.Length; index++)
				{
					inputBytes2Compare[index] = inputBytesCopy[index];
					if (index == 0)
					{
						inputBytes2Compare[index] = (byte) (inputBytes2Compare[index] + 1);
					}
				}
				
				UserData_26_BlockStateAll userData2Compare = new UserData_26_BlockStateAll(userData.Device, userData.Address, userData.AddressAddOn,
							inputBytes2Compare, userData.GetCopyOfOutputBytes(), userData.GetCopyOfDisruptionBytes());
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// different output bytes - one more member
				byte[] outputBytesCopy = userData.GetCopyOfOutputBytes();
				byte[] outputBytes2Compare = new byte[outputBytesCopy.Length + 1];
				for (int index = 0; index < outputBytesCopy.Length; index++)
				{
					outputBytes2Compare[index] = outputBytesCopy[index];
				}
				outputBytes2Compare[outputBytesCopy.Length] = 0x55;

				UserData_26_BlockStateAll userData2Compare = new UserData_26_BlockStateAll(userData.Device, userData.Address, userData.AddressAddOn,
							userData.GetCopyOfInputBytes(), outputBytes2Compare, userData.GetCopyOfDisruptionBytes());
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// different disruption bytes - one different member
				byte[] disruptionBytesCopy = userData.GetCopyOfDisruptionBytes();
				byte[] disruptionBytes2Compare = new byte[disruptionBytesCopy.Length];
				for (int index = 0; index < disruptionBytesCopy.Length; index++)
				{
					disruptionBytes2Compare[index] = disruptionBytesCopy[index];
					if (index == 0)
					{
						disruptionBytes2Compare[index] = (byte)(disruptionBytesCopy[index] + 1);
					}
				}

				UserData_26_BlockStateAll userData2Compare = new UserData_26_BlockStateAll(userData.Device, userData.Address, userData.AddressAddOn,
							userData.GetCopyOfInputBytes(), userData.GetCopyOfOutputBytes(), disruptionBytes2Compare);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}
		}

		[TestMethod]
		[Owner("Frank Eppink")]
		public void Test02_Equals_BytesAllNull()
		{
			UserData_26_BlockStateAll userData = new UserData_26_BlockStateAll(0x67, 0x23, 0x54, null, null, null);

			{
				// completely different type - NOT equal
				object dummyObject = new object();
				Assert.IsFalse(userData.Equals(dummyObject));
			}

			{
				// different derived type 
				UserData_11_Error userData2Compare = new UserData_11_Error(eErrorCode.DataOutOfRange, 0x99);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// same object - equal
				UserData_26_BlockStateAll userData2Compare = new UserData_26_BlockStateAll(userData.Device, userData.Address, userData.AddressAddOn,
							userData.GetCopyOfInputBytes(), userData.GetCopyOfOutputBytes(), userData.GetCopyOfDisruptionBytes());
				Assert.IsTrue(userData.Equals(userData2Compare));
			}

			{
				// different device
				UserData_26_BlockStateAll userData2Compare = new UserData_26_BlockStateAll((byte)(userData.Device + 1), userData.Address, userData.AddressAddOn,
							userData.GetCopyOfInputBytes(), userData.GetCopyOfOutputBytes(), userData.GetCopyOfDisruptionBytes());
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// different address
				UserData_26_BlockStateAll userData2Compare = new UserData_26_BlockStateAll(userData.Device, (byte)(userData.Address + 1), userData.AddressAddOn,
							userData.GetCopyOfInputBytes(), userData.GetCopyOfOutputBytes(), userData.GetCopyOfDisruptionBytes());
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// different AddressAddOn
				UserData_26_BlockStateAll userData2Compare = new UserData_26_BlockStateAll(userData.Device, userData.Address, (byte)(userData.AddressAddOn + 1),
							userData.GetCopyOfInputBytes(), userData.GetCopyOfOutputBytes(), userData.GetCopyOfDisruptionBytes());
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// different input bytes - one more member
				byte[] inputBytesCopy = userData.GetCopyOfInputBytes();
				byte[] inputBytes2Compare = new byte[inputBytesCopy.Length + 1];
				for (int index = 0; index < inputBytesCopy.Length; index++)
				{
					inputBytes2Compare[index] = inputBytesCopy[index];
				}
				inputBytes2Compare[inputBytesCopy.Length] = 0x55;

				UserData_26_BlockStateAll userData2Compare = new UserData_26_BlockStateAll(userData.Device, userData.Address, userData.AddressAddOn,
							inputBytes2Compare, userData.GetCopyOfOutputBytes(), userData.GetCopyOfDisruptionBytes());
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// different output bytes - one more member
				byte[] outputBytesCopy = userData.GetCopyOfOutputBytes();
				byte[] outputBytes2Compare = new byte[outputBytesCopy.Length + 1];
				for (int index = 0; index < outputBytesCopy.Length; index++)
				{
					outputBytes2Compare[index] = outputBytesCopy[index];
				}
				outputBytes2Compare[outputBytesCopy.Length] = 0x55;

				UserData_26_BlockStateAll userData2Compare = new UserData_26_BlockStateAll(userData.Device, userData.Address, userData.AddressAddOn,
							userData.GetCopyOfInputBytes(), outputBytes2Compare, userData.GetCopyOfDisruptionBytes());
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// different disruption bytes - one different member
				byte[] disruptionBytesCopy = userData.GetCopyOfDisruptionBytes();
				byte[] disruptionBytes2Compare = new byte[disruptionBytesCopy.Length + 1];
				for (int index = 0; index < disruptionBytesCopy.Length; index++)
				{
					disruptionBytes2Compare[index] = disruptionBytesCopy[index];					
				}
				disruptionBytes2Compare[disruptionBytesCopy.Length] = 0x55;

				UserData_26_BlockStateAll userData2Compare = new UserData_26_BlockStateAll(userData.Device, userData.Address, userData.AddressAddOn,
							userData.GetCopyOfInputBytes(), userData.GetCopyOfOutputBytes(), disruptionBytes2Compare);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}
		}

		[TestMethod]
		[Owner("Frank Eppink")]
		public void Test03_GetHashCode()
		{
			{
				UserData_26_BlockStateAll userData = new UserData_26_BlockStateAll(0x67, 0x23, 0x54,
					new byte[] { 0xff, 0xaa, 0x55 }, new byte[] { 0x11, 0x33 }, new byte[] { 0xff });
				int hashCode = userData.GetHashCode();
			}

			{
				UserData_26_BlockStateAll userData = new UserData_26_BlockStateAll(0x67, 0x23, 0x54, null, null, null);
				int hashCode = userData.GetHashCode();
			}

			{
				UserData_26_BlockStateAll userData = new UserData_26_BlockStateAll(0x67, 0x23, 0x54, new byte[0], new byte[0], new byte[0]);
				int hashCode = userData.GetHashCode();
			}
		}

		[TestMethod]
		[Owner("Frank Eppink")]
		public void Test04_ToString()
		{
			{
				UserData_26_BlockStateAll userData = new UserData_26_BlockStateAll(0x67, 0x23, 0x54,
					new byte[] { 0xff, 0xaa, 0x55 }, new byte[] { 0x11, 0x33 }, new byte[] { 0xff });
				string stringResult = userData.ToString();
				Assert.IsNotNull(stringResult);
			}

			{
				UserData_26_BlockStateAll userData = new UserData_26_BlockStateAll(0x67, 0x23, 0x54, null, null, null);
				string stringResult = userData.ToString();
				Assert.IsNotNull(stringResult);
			}

			{
				UserData_26_BlockStateAll userData = new UserData_26_BlockStateAll(0x67, 0x23, 0x54, new byte[0], new byte[0], new byte[0]);
				string stringResult = userData.ToString();
				Assert.IsNotNull(stringResult);
			}
		}
	}
}
